﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.DataEntity;
using Cosmetic.Logic;
namespace WebApp.Management
{
    public partial class userEites : PageBase2
    {
        private UserManager m_userManger = new UserManager();
        private RoleManager m_RoleManager = new RoleManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.SignInUser1 == null)
            {
                Session.Remove("SignInUser1");
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('请先登录权限!');window.top.location.href='/Management/indexs.aspx';", true);
                return;
            }
            if (!IsPostBack)
            {
                Cosmetic.DataEntity.User theUser = this.SignInUser1;
                if (!this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Admin))
                {
                    Session.Remove("SignInUser1");
                    this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('你没有管理员权限!');window.top.location.href='/Management/indexs.aspx';", true);
                    return;
                }
            }
            if (!IsPostBack)
            {
            this.LoadProduct(new Guid(this.Request.QueryString["PID"]));
            }
        }

        private void LoadProduct(Guid  id)
        {
          
            User theuser = this.m_userManger.GetUserById(id );
            this.TextBox4.Text = theuser.tel;
            this.TextBox1.Text = theuser.Password;
            this.TextBox2.Text = Convert.ToString (theuser.Balance);
            this.DropDownList2.SelectedValue = theuser.Level;
        }

        protected void btnEditProduct_Click(object sender, EventArgs e)
        {
            User theuser1 = this.m_userManger.GetUserById(new Guid(this.Request.QueryString["PID"]));
            string m_CD = this.Request.QueryString["PID"];
            ////theuser1.Balance = Convert .ToDecimal( this.TextBox2.Text);
            ////theuser1.tel = this.TextBox4.Text;
            ////theuser1.Password = this.TextBox1.Text;
            ////theuser1.Level = 
            ////m_userManger.Update();
           UserManager.UpdateInformations(new Guid(m_CD),  Convert .ToDecimal(this.TextBox2.Text),this.DropDownList2.SelectedValue.ToString());
            this.Page.Response.Redirect("userManger.aspx");

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.Page.Response.Redirect("userManger.aspx");
        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}
